const Router = require("koa-router");
const pool = require('../database.js');
const {getList,postData,putData,deleteData,anthVertify} =require('../common/middleware.js')
const router = new Router({
  prefix: "/link",
});
router.get("/",anthVertify, async(ctx, next) => {
  await getList(ctx,{table:'link',otherState:`WHERE userId=${ctx.user.id}`})
});
router.post("/",async(ctx, next) => {
  let data=ctx.request.body
  let result2= await getList(ctx,{table:'promotion',otherState:`WHERE link=${data.link} && id=${data.eid}`,notList:true,notBody:true})
  let obj={
    userId:result2.data.userId,
    proId:data.eid,
    linkName:data.linkName,
    linkCompony:data.linkCompony,
    linkDescribe:data.linkDescribe,
    linkPhone:data.linkPhone,
  }
  console.log(obj);
   await postData({table:'link',data:obj,ctx:ctx})
});
module.exports = router;
